package cn.wubo.vrr.help.service.impl;

import cn.wubo.vrr.help.entity.EhrPerson;
import cn.wubo.vrr.help.repository.EhrPersonRepository;
import cn.wubo.vrr.help.service.EhrPersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
public class EhrPersonServiceImpl implements EhrPersonService {

    @Autowired
    EhrPersonRepository ehrPersonRepository;

    @Override
    public EhrPerson save(EhrPerson p) {
        EhrPerson query = new EhrPerson();
        query.setOprid(p.getOprid());
        Optional<EhrPerson> res = ehrPersonRepository.findOne(Example.of(query));
        if(res.isPresent()){
            p.setId(res.get().getId());
        }else{
            p = ehrPersonRepository.save(p);
        }
        return  p;
    }
}
